package com.ddwl.goods.dao;

import cn.hutool.core.util.StrUtil;
import com.ddwl.common.constant.Constant;
import com.ddwl.common.dao.TkDao;
import com.ddwl.goods.dao.mapper.GoodsProfitMapper;
import com.ddwl.goods.dao.model.GoodsProfit;
import com.ddwl.schema.bo.goods.QueryGoodsProfitBo;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.Arrays;
import java.util.List;

/**
 * 类GoodsProfitDao.java的实现描述：商品分润dao
 *
 * @author zach
 * @Date :2020-05-26 10:47.
 */
@Repository
public class GoodsProfitDao extends TkDao<GoodsProfitMapper, GoodsProfit> {


    public GoodsProfit getGoodsProfit(String targetId,Integer targetType){
        GoodsProfit goodsProfit = new GoodsProfit();
        goodsProfit.setTargetId(targetId);
        goodsProfit.setTargetType(targetType);
        return selectOne(goodsProfit);
    }


    public List<GoodsProfit> queryGoodsProfits(QueryGoodsProfitBo bo){
        Example example = getExample();
        example.and().andEqualTo("targetId",bo.getTargetId())
                .andEqualTo("targetType",bo.getTargetType())
                .andEqualTo("shopId",bo.getShopId())
                .andEqualTo("status",bo.getStatus());
        if(StrUtil.isNotBlank(bo.getTargetIds())){
            example.and().andIn("targetId", Arrays.asList(bo.getTargetIds().split(Constant.DEFAULT_SEPARATOR)));
        }
        return baseMapper.selectByExample(example);
    }

    public GoodsProfit getShopGoodsProfit(String id, String shopId) {
        return baseMapper.getShopGoodsProfit(id,shopId);
    }


    public GoodsProfit queryGoodsProfit(String id, String shopId){
        Example example = getExample();
        example.and().andEqualTo("id",id)
                .andEqualTo("shopId",shopId);
        return baseMapper.selectOneByExample(example);
    }
}
